package com.cheer.ba.http;

import android.app.Application;
import android.content.Context;
import android.content.Intent;

import com.bigkoo.svprogresshud.SVProgressHUD;
import com.cheer.ba.constant.IntentKey;
import com.cheer.ba.constant.ReturnCode;
import com.cheer.ba.model.ResponseData;
import com.cheer.ba.view.activity.MainAty;

/**
 * 作者：Administrator on 2016/8/20 0020 16:07
 * 功能：
 * 说明：
 */
public class HandleRetCode {

    /**
     * 处理后台返回值，弹出提醒
     *
     * @author HQ
     * created at 2017/3/6 0006 11:00
     */
    public static void handler(final Context context, ResponseData responseData, boolean isShowMsg, String msg) {
        if (responseData.getRet() == ReturnCode.FAIL_REMIND_1) {
            if (null != context) {
                SVProgressHUD.dismiss(context);
                if (isShowMsg) {
                    SVProgressHUD.showInfoWithStatus(context, responseData.getMsg());
                }
            }
        } else if (responseData.getRet() == ReturnCode.FAIL_REMIND_2) {
            if (null != context) {
                SVProgressHUD.dismiss(context);
                if (isShowMsg) {
                    SVProgressHUD.showInfoWithStatus(context, msg);
                }
            }
        }
//        else if (responseData.getRet() == ReturnCode.USER_EXPIRE) {
//            handlerExpire(context, responseData);
//        }
    }

    /**
     * 用户过期
     *
     * @author HQ
     * created at 2017/3/6 0006 11:06
     */
    public static boolean handlerExpire(final Context mContext, ResponseData responseData) {
        if (responseData.getRet() == ReturnCode.USER_EXPIRE) {
            if (null != mContext) {
                Intent intent = new Intent(mContext, MainAty.class);
                if (mContext instanceof Application) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                }
                intent.putExtra(IntentKey.General.KEY_TYPE, ReturnCode.USER_EXPIRE);
                mContext.startActivity(intent);
                return true;
            }
        }
        return false;
    }
}
